package com.suarte.webapp.action;

import com.suarte.core.PaymentMethod;
import java.io.Serializable;
import org.appfuse.service.GenericManager;

/**
 * @date   Jan 21, 2013
 * @author Ggutierrez
 */
public class PaymentMethodForm extends BasePage implements Serializable {
    private GenericManager<PaymentMethod, Long> paymentMethodManager;
    private PaymentMethod paymentMethod = new PaymentMethod();
    private Long id;

    public void setPaymentMethodManager(GenericManager<PaymentMethod, Long> paymentMethodManager) {
        this.paymentMethodManager = paymentMethodManager;
    }

    public PaymentMethod getPaymentMethod() {
        return paymentMethod;
    }

    public void setPaymentMethod(PaymentMethod paymentMethod) {
        this.paymentMethod = paymentMethod;
    }    

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String delete() {
        paymentMethodManager.remove(paymentMethod.getId());
        addMessage("paymentMethod.deleted");

        return "list";
    }

    public String edit() {
        if (id != null) {
            paymentMethod = paymentMethodManager.get(id);
        } else {
            paymentMethod = new PaymentMethod();
        }

        return "edit";
    }

    public String add() {
        paymentMethod = new PaymentMethod();

        return "add";
    }

    public String save() {
        boolean isNew = (paymentMethod.getId() == null);
        paymentMethodManager.save(paymentMethod);

        String key = (isNew) ? "paymentMethod.added" : "paymentMethod.updated";
        addMessage(key);

        if (isNew) {
            return "list";
        } else {
            return "edit";
        }
    }
}
